﻿using System;
using System.Data.Entity;
using YWM.DependencyInjection;

namespace YWM.EntityFramework.Extensions
{
    public static class DbContextExtensions
    {
        public static void AddDb<TDbContext>(this MyContainerBuilder containerBuilder) where TDbContext : DbContext
        {
            Type dbContextType = typeof(TDbContext);
            // 存储数据库上下文
            Penetrates.DbContextDescriptors.AddOrUpdate(dbContextType.FullName, dbContextType, (key, value) => dbContextType);
            // 注册数据库上下文
            containerBuilder.RegisterType<TDbContext>(DependencyLifeTime.Scoped);
        }
    }
}